package com.whfc.ms.api.md.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.entity.dto.warn.AppWarnDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.md.service.MdIndexBoardService;
import com.whfc.uni.dto.CarBoardAnalysisDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author: hw
 * @date: 2021-11-18 16:04
 * @description: 数据大屏 - 首页接口
 */
@RestController
@RequestMapping("/ms/api/md/board")
public class MdIndexBoardController extends BaseController {

    @Autowired
    private MdIndexBoardService mdIndexBoardService;


    @GetMapping("/car/record/analysis")
    public Result carBoardAnalysis(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                   @RequestParam("deptId") Integer deptId,
                                   @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                   @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        logger.info("大屏-车辆记录，loginer:{},deptId:{},startDate:{},endDate：{}", user.getUsername(), deptId, startDate, endDate);
        CarBoardAnalysisDTO data = mdIndexBoardService.carBoardAnalysis(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

    @GetMapping("/car/record/analysis2")
    public Result carBoardAnalysis2(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                    @RequestParam("deptId") Integer deptId,
                                    @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                    @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        logger.info("大屏-车辆记录，loginer:{},deptId:{},startDate:{},endDate：{}", user.getUsername(), deptId, startDate, endDate);
        CarBoardAnalysisDTO data = mdIndexBoardService.carBoardAnalysis2(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

    @GetMapping("/fsdm/list")
    public Result boardMilestoneList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                     @RequestParam("planId") Long planId) {
        logger.info("大屏-计划进度，loginer:{},planId：{}", user.getUsername(), planId);
        return ResultUtil.success(Collections.emptyList());
    }

    @GetMapping("/warn/list")
    public Result warnList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                           @RequestParam("deptId") Integer deptId) {
        logger.info("大屏-获取报警列表, loginer:{}, deptId:{}", user.getUsername(), deptId);
        List<AppWarnDTO> warnList = mdIndexBoardService.getWarnList(deptId);
        return ResultUtil.success(new ListData<>(warnList));
    }
}
